home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / allfiles / angry / intro.dir / 00044_Script_xxxgravity < prev    next >
Text File  |  1999-03-01  |  3KB  |  155 lines

  1. property mySpr, mass, velocity, location
  2. property timeScale, scale, systemOrigin
  3. property frozen, activated
  4. property animCount, myAnim
  5. property pSoftSound, pHardSound
  6.  
  7. global stageWidth, stageHeight
  8.  
  9. on new me, thisSpr, thisAnim, thisSound
  10.   
  11.   set mySpr = thisSpr
  12.   set myAnim = thisAnim
  13.   set timeScale = 50 -- seconds per update
  14.   set scale = 5 -- units per pixel
  15.   
  16.   set pSoftSound = 0
  17.   set pHardSound = 0
  18.   
  19.   if thisSound then
  20.     set pSoftSound = thisSound
  21.     set pHardSound = thisSound + 1
  22.   end if
  23.   
  24.   set stageWidth = the stageRight - the stageLeft
  25.   set stageHeight = the stageBottom - the stageTop
  26.   
  27.   set systemOrigin = [ #X:stageWidth/2, #Y:stageHeight/2 ]
  28.   
  29.   --  x mySpr, TRUE
  30.   
  31.   set frozen = FALSE
  32.   set activated = FALSE
  33.   
  34.   set mass = 65
  35.   
  36.   set velocity = [#X:0, #Y:0]
  37.   
  38.   setloc me
  39.   
  40.   return me
  41. end new
  42.  
  43.  
  44. on setloc me
  45.   set newX = (the locH of sprite(mySpr) - the X of systemOrigin) * scale
  46.   set newY = (the locV of sprite(mySpr) - the Y of systemOrigin) * scale
  47.   
  48.   set location = [#X:newX, #Y:newY]
  49. end setloc
  50.  
  51.  
  52. on gravitate me
  53.   ---------
  54.   
  55.   set mouseMass = mass / 2
  56.   
  57.   --------
  58.   
  59.   if mySpr = 12 then
  60.     set N = flyGravity(mySpr, mass, point(the mouseH, the mouseV),¼
  61.                      mouseMass, 0, "attract") -- the mouse
  62.   else
  63.     set N = calcGravity(mySpr, mass) -- jean paul's
  64.   end if
  65.   
  66.   push me, N
  67.   
  68. end gravitate
  69.  
  70.  
  71. on push me, theForce
  72.   
  73.   set acceleration = theForce / mass
  74.   
  75.   set deltaVelocity = acceleration * timeScale
  76.   
  77.   set velocity = velocity + deltaVelocity
  78.   
  79.   -- bounce
  80.   
  81.   set playSound = FALSE
  82.   
  83.   if the bottom of sprite(mySpr) > stageHeight then
  84.     if the Y of velocity > 0 then
  85.       set the Y of velocity to - the Y of velocity
  86.       set playSound = TRUE
  87.     end if
  88.   end if
  89.   
  90.   if the top of sprite(mySpr) < 0 then
  91.     if the Y of velocity < 0 then
  92.       set the Y of velocity to - the Y of velocity
  93.       set playSound = TRUE
  94.     end if
  95.   end if  
  96.   
  97.   if the left of sprite(mySpr) < 0 then
  98.     if the X of velocity < 0 then
  99.       set the X of velocity to - the X of velocity
  100.       set playSound = TRUE
  101.     end if
  102.   end if
  103.   
  104.   if the right of sprite(mySpr) > stageWidth then
  105.     if the X of velocity > 0 then
  106.       set the X of velocity to - the X of velocity
  107.       set playSound = TRUE
  108.     end if
  109.   end if
  110.   
  111.   if playSound AND pSoftSound AND random(4) = 3 then
  112.     
  113.     set maxVeloc = max(abs(the X of velocity), abs(the Y of velocity))
  114.     
  115.     if maxVeloc > 300 then puppetSound 2, pHardSound
  116.     else puppetSound 2, pSoftSound
  117.     
  118.   end if
  119.   
  120.   
  121.   move me
  122.   
  123. end push
  124.  
  125.  
  126. on move me
  127.   
  128.   set location = location + velocity
  129.   
  130.   set newLocH = the X of systemOrigin + (integer(the X of location) / scale)
  131.   set newLocV = the Y of systemOrigin + (integer(the Y of location) / scale)
  132.   
  133.   set the locH of sprite(mySpr) = newLocH
  134.   set the locV of sprite(mySpr) = newLocV
  135.   
  136. end move
  137.  
  138.  
  139. on animLoop me   -- art animation
  140.   
  141.   
  142.   if animCount <> count(myAnim) then
  143.     set animCount = animCount + 1
  144.     if animCount >= count(myAnim) then
  145.       set animCount = count(myAnim)      
  146.     end if
  147.     set the member of sprite(mySpr) = member getAt(myAnim, animCount)
  148.   else if animCount = count(myAnim) then
  149.     set animCount = 0
  150.     
  151.   end if
  152.   
  153. end animLoop
  154.  
  155.